#include "ccnc.h"
#include <cstdio>
#include <cstring>

ccnc::ccnc()
{
}

void ccnc::hardcode_location(location loc_arr[])
{
	//load hardcoding
		loc_arr[0].x = 384;
		loc_arr[0].y = 256;

		loc_arr[1].x = 320;
		loc_arr[1].y = 256;

		loc_arr[2].x = 256;
		loc_arr[2].y = 256;

		loc_arr[3].x = 192;
		loc_arr[3].y = 256;

		loc_arr[4].x = 128;
		loc_arr[4].y = 256;

		loc_arr[5].x = 0;
		loc_arr[5].y = 256;

		loc_arr[6].x = 0;
		loc_arr[6].y = 384;

		loc_arr[7].x = 0;
		loc_arr[7].y = 448;

		loc_arr[8].x = 0;
		loc_arr[8].y = 512;

		loc_arr[9].x = 0;
		loc_arr[9].y = 576;

		loc_arr[10].x = 0;
		loc_arr[10].y = 640;

		loc_arr[11].x = 128;
		loc_arr[11].y = 640;

		loc_arr[12].x = 192;
		loc_arr[12].y = 640;

		loc_arr[13].x = 256;
		loc_arr[13].y = 640;

		loc_arr[14].x = 320;
		loc_arr[14].y = 640;

		loc_arr[15].x = 384;
		loc_arr[15].y = 640;

		loc_arr[16].x = 384;
		loc_arr[16].y = 576;

		loc_arr[17].x = 384;
		loc_arr[17].y = 512;

		loc_arr[18].x = 384;
		loc_arr[18].y = 448;

		loc_arr[19].x = 384;
		loc_arr[19].y = 384;

	//special feature hardcoding

	for (int i = 0; i < 20; i++) //initialization of location, needs hardcoding of x,y
	{
		if (i == 0 || i == 4 || i == 5 || i == 9 || i == 10 || i == 11 || i == 15 || i == 18)
		{
			loc_arr[i].is_property = 0;
			loc_arr[i].location_code = i;
		}
		else
		{
			loc_arr[i].is_property = 1;
			loc_arr[i].location_code = i;
		}
	}
	
	//PROPERTY name and price and rent hardcoding:  (utlities are 6 and 13)
	strcpy_s(loc_arr[1].name, "WHITECHAPEL ROAD");
	loc_arr[1].price = 60;
	loc_arr[1].rent = 5;

	strcpy_s(loc_arr[2].name, "KINGS CROSS STATION");
	loc_arr[2].price = 200;
	loc_arr[2].rent = 25;
	loc_arr[2].is_station = 1;

	strcpy_s(loc_arr[3].name, "EUSTON ROAD");
	loc_arr[3].price = 100;
	loc_arr[3].rent = 10;

	strcpy_s(loc_arr[6].name, "ELECTRIC COMPANY");
	loc_arr[6].price = 150;
	loc_arr[6].rent = 15;
	loc_arr[6].is_utility = 1;

	strcpy_s(loc_arr[7].name, "MARYLEBONE STATION");
	loc_arr[7].price = 200;
	loc_arr[7].rent = 25;
	loc_arr[7].is_station = 1;

	strcpy_s(loc_arr[8].name, "BOW STREET");
	loc_arr[8].price = 180;
	loc_arr[8].rent = 18;

	strcpy_s(loc_arr[12].name, "FENCHURCH ST. STATION");
	loc_arr[12].price = 200;
	loc_arr[12].rent = 25;
	loc_arr[12].is_station = 1;

	strcpy_s(loc_arr[13].name, "WATER WORKS");
	loc_arr[13].price = 150;
	loc_arr[13].rent = 15;
	loc_arr[13].is_utility = 1;

	strcpy_s(loc_arr[14].name, "PICCADILLY");
	loc_arr[14].price = 280;
	loc_arr[14].rent = 30;

	strcpy_s(loc_arr[16].name, "BOND STREET");
	loc_arr[16].price = 320;
	loc_arr[16].rent = 35;

	strcpy_s(loc_arr[17].name, "LIVERPOOL ST. STATION");
	loc_arr[17].price = 200;
	loc_arr[17].rent = 25;
	loc_arr[17].is_station = 1;

	strcpy_s(loc_arr[19].name, "MAYFAIR");
	loc_arr[19].price = 400;
	loc_arr[19].rent = 50;

	//OTHER LOCATION HARDCODING

	strcpy_s(loc_arr[0].name, "GO");
	strcpy_s(loc_arr[4].name, "CHANCE");
	strcpy_s(loc_arr[5].name, "JUST VISITING/IN JAIL");
	strcpy_s(loc_arr[9].name, "COMMUNITY CHEST");
	strcpy_s(loc_arr[10].name, "FREE PARKING");
	strcpy_s(loc_arr[11].name, "CHANCE");
	strcpy_s(loc_arr[15].name, "GO TO JAIL");
	strcpy_s(loc_arr[18].name, "COMMUNITY CHEST");
}

char *ccnc::chance(player &p, bank &b, location loc_arr[])
{
	int i;
	i = rand() % 6;
	char str[1000];
	if (i == 0)
	{
		
		p.money += 200;
		b.fund -= 200;
		p.x = 384;
		p.y = 256;
		p.current_location_code = 0;
		sprintf_s(str, ": Advance to Go, Collect 200");
		return str;
	}
	else if (i == 1)
	{
		
		p.is_get_out_card = 1; //needs more changing 
		sprintf_s(str, ": Get out of Jail Free Card");
		return str;
	}
	else if (i == 2)
	{
		sprintf_s(str, ": Bank pays you dividend of $50");
		p.money += 50;
		b.fund -= 50;
		return str;
	}
	else if (i == 3)
	{
		sprintf_s(str, ": Pay poor tax of $15");
		if (p.money < 15)
		{
			p.is_eliminated = 1;
			for (int x = 0; x < 20; x++)
			{
				if (p.properties[x] == 1)
				{
					p.properties[x] = 0;
					loc_arr[x].owner_code = -1;
					b.fund += loc_arr[x].price / 2;
				}
			}
			strcat_s(str, ". Couldn't pay. Eliminated next");
			return str;
		}
		p.money -= 15;
		b.fund += 15;
		return str;
	}
	else if (i == 4)
	{
		sprintf_s(str, ": Drunk in Charge, Pay $15");
		if (p.money < 15)
		{
			p.is_eliminated = 1;
			for (int x = 0; x < 20; x++)
			{
				if (p.properties[x] == 1)
				{
					p.properties[x] = 0;
					loc_arr[x].owner_code = -1;
					b.fund += loc_arr[x].price / 2;
				}
			}
			strcat_s(str, ". Couldn't pay. Eliminated next");
			return str;
		}
		p.money -= 15;
		b.fund += 15;
		return str;
	}
	else if (i == 5)
	{
		sprintf_s(str, ": Go to Jail");
		p.is_jail = 1;
		p.turns_since_free = 3;
		p.current_location_code = 5;
		p.x = 0;
		p.y = 256;//might need jail modifciation
		return str;
	}

}

char *ccnc::community_chest(player &p, bank &b, location loc_arr[])
{
	int i;
	i = rand() % 6;
	char str[1000];
	if (i == 0)
	{
		
		p.money += 200;
		b.fund -= 200;
		p.x = 384;
		p.y = 256;
		p.current_location_code = 0;
		sprintf_s(str, ": Advance to Go, Collect 200");
		return str;
	}
	if (i == 1)
	{
		sprintf_s(str, ": Bank pays you dividend of $200");
		p.money += 200;
		b.fund -= 200;
		return str;
	}
	if (i == 2)
	{
		sprintf_s(str, ": Doctor's fees. You pay $15");
		if (p.money < 15)
		{
			p.is_eliminated = 1;
			for (int x = 0; x < 20; x++)
			{
				if (p.properties[x] == 1)
				{
					p.properties[x] = 0;
					loc_arr[x].owner_code = -1;
					b.fund += loc_arr[x].price / 2;
				}
			}
			strcat_s(str, ". Couldn't pay. Eliminated next");
			return str;
		}
		p.money -= 15;
		b.fund += 15;
		return str;
	}
	if (i == 3)
	{

		p.is_get_out_card = 1; //needs more changing 
		sprintf_s(str, ": Get out of Jail Free Card");
		return str;
	}
	if (i == 4)
	{
		sprintf_s(str, ": You inherit $100");
		p.money += 100;
		b.fund -= 100;
		return str;
	}
	if (i == 5)
	{
		sprintf_s(str, ": School fees. You pay $150");
		if (p.money < 150)
		{
			p.is_eliminated = 1;
			for (int x = 0; x < 20; x++)
			{
				if (p.properties[x] == 1)
				{
					p.properties[x] = 0;
					loc_arr[x].owner_code = -1;
					b.fund += loc_arr[x].price / 2;
				}
			}
			strcat_s(str, ". Couldn't pay. Eliminated next");
			return str;
		}
		p.money -= 150;
		b.fund += 150;
		return str;
	}
}

ccnc::~ccnc()
{
}
